/**
 * Created by Ession on 2016/12/14.
 */
var overview = {
    init: function () {
        var _this = this;
        document.title = "首页";
        _this.initCompanyInfo(function (data) {
            var temp = Util.template($("#overview-template").html(),{imageList:data.homeImgs_Ids});
            $(".main_body").html(temp);
            Carousel.init($(".pictureSlider"));
            _this.initVisitorList();
            _this.attendanceList()
        })
    },
    settings:{
        CompanyInfo:{}
    },
    initCompanyInfo: function (fn) {
        var _this = this;
        Util.ajaxRequest({
            type: "get",
            url: interfaceURL.getCompany(),
            dataType: "json",
            success: function (data) {
                if(data.code==200){
                    _this.settings.CompanyInfo = data.result;
                    $.isFunction(fn)?fn(data.result):"";
                }
            }
        });
    },
    initVisitorList: function (page) {
        var _this = this;
        Util.ajaxRequest({
            type: "get",
            url: interfaceURL.visitorList(),
            dataType: "json",
            data:{
                pageNum:Util.isEmpty(page)?1:page,
                pageSize:pageInfo.pageSize($(".my-visitor-table.visitor .my-table"))
            },
            success: function (data) {
                if(data.code==200){
                    $(".my-visitor-table.visitor .my-table").cakeTable({
                        head: [
                            {field: "name", name: "访客姓名"},
                            {field: "visittime", name: "访客时间"},
                            {field: "state", name: "访客状态",rule:{
                                0:"已预约",
                                1:"访问中",
                                2:"访问结束",
                                3:"已撤销"
                            }}
                        ],
                        sort: false,
                        columns: data.result.results,
                        showPage: true,
                        pageInfo: data.result.pagination2,
                        align: "center",
                        pageType: "out",
                        showNum:false,
                        page: function (page) {
                            _this.initVisitorList(page)
                        }
                    })
                }
            }
        });
    },
    attendanceList: function (page) {
        var _this = this;
        Util.ajaxRequest({
            type: "get",
            url: interfaceURL.attendancdList(),
            dataType: "json",
            data: {
                pageNum:Util.isEmpty(page)?1:page,
                pageSize:pageInfo.pageSize($(".my-visitor-table.checkon .my-table"))
            },
            success: function (data) {
                if(data.code == 200){
                    $(".my-visitor-table.checkon .my-table").cakeTable({
                        head: [
                            {field: "recordDate", name: "日期",format:"date"},
                            {field: "userRealName", name: "姓名"},
                            {field: "checkIn", name: "上班打卡时间",format:"time"},
                            {field: "checkOut", name: "下班打卡时间",format:"time"},
                            {field: "checkType", name: "状态",rule:{
                                1:"<span class='blue'>[正常考勤]</span>",
                                2:"<span class='red'>[迟到]</span>",
                                3:"<span class='red'>[早退]</span>",
                                4:"<span class='red'>[未打卡]</span>",
                                5:"<span class='red'>[迟到][早退]</span>"
                            }}
                        ],
                        sort: false,
                        columns: data.result.results,
                        showPage: true,
                        pageInfo: data.result.pagination2,
                        align: "center",
                        pageType: "out",
                        showNum:false,
                        page: function (page) {
                            _this.attendanceList(page)
                        }
                    })
                }
            }
        })
    }
};

